<?php

namespace app\common\library;
class Hypy
{
    private static $pinyinTable = array(
        'a' => '啊', 'ai' => '哀', 'an' => '安', 'ang' => '昂', 'ao' => '凹',
        'ba' => '八', 'bai' => '百', 'ban' => '班', 'bang' => '帮', 'bao' => '包',
        'bei' => '悲', 'ben' => '奔', 'beng' => '崩', 'bi' => '逼', 'bian' => '边',
        'biao' => '标', 'bie' => '别', 'bin' => '宾', 'bing' => '兵', 'bo' => '波',
        'bu' => '不', 'ca' => '擦', 'cai' => '才', 'can' => '参', 'cang' => '仓',
        'cao' => '草', 'ce' => '册', 'ceng' => '层', 'cha' => '查', 'chai' => '柴',
        'chan' => '产', 'chang' => '长', 'chao' => '超', 'che' => '车', 'chen' => '沉',
        'cheng' => '成', 'chi' => '吃', 'chong' => '充', 'chou' => '抽', 'chu' => '出',
        'chuai' => '揣', 'chuan' => '川', 'chuang' => '创', 'chui' => '吹', 'chun' => '春',
        'chuo' => '戳', 'ci' => '词', 'cong' => '从', 'cou' => '凑', 'cu' => '粗',
        'cuan' => '窜', 'cui' => '崔', 'cun' => '村', 'cuo' => '错', 'da' => '大',
        'dai' => '呆', 'dan' => '单', 'dang' => '当', 'dao' => '刀', 'de' => '得',
        'deng' => '灯', 'di' => '低', 'dian' => '点', 'diao' => '刁', 'die' => '跌',
        'ding' => '丁', 'diu' => '丢', 'dong' => '冬', 'dou' => '斗', 'du' => '读',
        'duan' => '端', 'dui' => '对', 'dun' => '吨', 'duo' => '多', 'e' => '鹅',
        'en' => '恩', 'er' => '儿', 'fa' => '发', 'fan' => '反', 'fang' => '方',
        'fei' => '飞', 'fen' => '分', 'feng' => '风', 'fo' => '佛', 'fou' => '否',
        'fu' => '福', 'ga' => '嘎', 'gai' => '该', 'gan' => '干', 'gang' => '刚',
        'gao' => '高', 'ge' => '歌', 'gei' => '给', 'gen' => '根', 'geng' => '耕',
        'gong' => '工', 'gou' => '狗', 'gu' => '古', 'gua' => '瓜', 'guai' => '乖',
        'guan' => '关', 'guang' => '光', 'gui' => '归', 'gun' => '滚', 'guo' => '国',
        'ha' => '哈', 'hai' => '还', 'han' => '汉', 'hang' => '航', 'hao' => '好',
        'he' => '和', 'hei' => '黑', 'hen' => '很', 'heng' => '横', 'hong' => '红',
        'hou' => '后', 'hu' => '胡', 'hua' => '华', 'huai' => '怀', 'huan' => '换',
        'huang' => '黄', 'hui' => '回', 'hun' => '昏', 'huo' => '火', 'ji' => '几',
        'jia' => '家', 'jian' => '间', 'jiang' => '江', 'jiao' => '交', 'jie' => '接',
        'jin' => '进', 'jing' => '京', 'jiong' => '炯', 'jiu' => '久', 'ju' => '举',
        'juan' => '卷', 'jue' => '决', 'jun' => '军', 'ka' => '卡', 'kai' => '开',
        'kan' => '看', 'kang' => '康', 'kao' => '考', 'ke' => '可', 'ken' => '肯',
        'keng' => '坑', 'kong' => '空', 'kou' => '口', 'ku' => '苦', 'kua' => '夸',
        'kuai' => '快', 'kuan' => '宽', 'kuang' => '狂', 'kui' => '亏', 'kun' => '困',
        'kuo' => '阔', 'la' => '拉', 'lai' => '来', 'lan' => '兰', 'lang' => '郎',
        'lao' => '老', 'le' => '了', 'lei' => '雷', 'leng' => '冷', 'li' => '里',
        'lia' => '俩', 'lian' => '连', 'liang' => '良', 'liao' => '辽', 'lie' => '列',
        'lin' => '林', 'ling' => '灵', 'liu' => '刘', 'long' => '龙', 'lou' => '楼',
        'lu' => '路', 'lv' => '吕', 'luan' => '乱', 'lue' => '略', 'lun' => '轮',
        'luo' => '罗', 'ma' => '马', 'mai' => '买', 'man' => '满', 'mang' => '忙',
        'mao' => '毛', 'me' => '么', 'mei' => '没', 'men' => '门', 'meng' => '蒙',
        'mi' => '米', 'mian' => '面', 'miao' => '苗', 'mie' => '灭', 'min' => '民',
        'ming' => '明', 'miu' => '谬', 'mo' => '莫', 'mou' => '某', 'mu' => '木',
        'na' => '拿', 'nai' => '奶', 'nan' => '南', 'nang' => '囊', 'nao' => '脑',
        'ne' => '呢', 'nei' => '内', 'nen' => '嫩', 'neng' => '能', 'ni' => '你',
        'nian' => '年', 'niang' => '娘', 'niao' => '鸟', 'nie' => '捏', 'nin' => '您',
        'ning' => '宁', 'niu' => '牛', 'nong' => '农', 'nu' => '奴', 'nv' => '女',
        'nuan' => '暖', 'nue' => '虐', 'nuo' => '诺', 'o' => '哦', 'ou' => '欧',
        'pa' => '怕', 'pai' => '排', 'pan' => '盘', 'pang' => '旁', 'pao' => '跑',
        'pei' => '培', 'pen' => '喷', 'peng' => '朋', 'pi' => '批', 'pian' => '片',
        'piao' => '飘', 'pie' => '撇', 'pin' => '品', 'ping' => '平', 'po' => '破',
        'pu' => '扑', 'qi' => '七', 'qia' => '恰', 'qian' => '前', 'qiang' => '强',
        'qiao' => '桥', 'qie' => '切', 'qin' => '亲', 'qing' => '青', 'qiong' => '穷',
        'qiu' => '秋', 'qu' => '去', 'quan' => '全', 'que' => '缺', 'qun' => '群',
        'ran' => '然', 'rang' => '让', 'rao' => '饶', 're' => '热', 'ren' => '人',
        'reng' => '扔', 'ri' => '日', 'rong' => '荣', 'rou' => '肉', 'ru' => '如',
        'ruan' => '软', 'rui' => '锐', 'run' => '润', 'ruo' => '若', 'sa' => '撒',
        'sai' => '赛', 'san' => '三', 'sang' => '桑', 'sao' => '扫', 'se' => '色',
        'sen' => '森', 'seng' => '僧', 'sha' => '杀', 'shai' => '晒', 'shan' => '山',
        'shang' => '上', 'shao' => '少', 'she' => '设', 'shen' => '深', 'sheng' => '生',
        'shi' => '是', 'shou' => '手', 'shu' => '书', 'shua' => '刷', 'shuai' => '帅',
        'shuan' => '栓', 'shuang' => '双', 'shui' => '水', 'shun' => '顺', 'shuo' => '说',
        'si' => '四', 'song' => '松', 'sou' => '搜', 'su' => '苏', 'suan' => '算',
        'sui' => '岁', 'sun' => '孙', 'suo' => '所', 'ta' => '他', 'tai' => '太',
        'tan' => '谈', 'tang' => '唐', 'tao' => '套', 'te' => '特', 'teng' => '疼',
        'ti' => '提', 'tian' => '天', 'tiao' => '条', 'tie' => '贴', 'ting' => '听',
        'tong' => '通', 'tou' => '头', 'tu' => '图', 'tuan' => '团', 'tui' => '推',
        'tun' => '吞', 'tuo' => '脱', 'wa' => '挖', 'wai' => '外', 'wan' => '万',
        'wang' => '王', 'wei' => '为', 'wen' => '文', 'weng' => '翁', 'wo' => '我',
        'wu' => '五', 'xi' => '西', 'xia' => '下', 'xian' => '先', 'xiang' => '相',
        'xiao' => '小', 'xie' => '谢', 'xin' => '新', 'xing' => '兴', 'xiong' => '胸',
        'xiu' => '休', 'xu' => '许', 'xuan' => '宣', 'xue' => '学', 'xun' => '寻',
        'ya' => '呀', 'yai' => '崖', 'yan' => '言', 'yang' => '阳', 'yao' => '要',
        'ye' => '也', 'yi' => '一', 'yin' => '因', 'ying' => '英', 'yo' => '哟',
        'yong' => '用', 'you' => '有', 'yu' => '于', 'yuan' => '元', 'yue' => '月',
        'yun' => '云', 'za' => '杂', 'zai' => '在', 'zan' => '咱', 'zang' => '脏',
        'zao' => '早', 'ze' => '则', 'zei' => '贼', 'zen' => '怎', 'zeng' => '曾',
        'zha' => '扎', 'zhai' => '摘', 'zhan' => '展', 'zhang' => '张', 'zhao' => '找',
        'zhe' => '这', 'zhen' => '真', 'zheng' => '正', 'zhi' => '知', 'zhong' => '中',
        'zhou' => '周', 'zhu' => '主', 'zhua' => '抓', 'zhuai' => '拽', 'zhuan' => '转',
        'zhuang' => '庄', 'zhui' => '追', 'zhun' => '准', 'zhuo' => '桌', 'zi' => '子',
        'zong' => '宗', 'zou' => '走', 'zu' => '租', 'zuan' => '钻', 'zui' => '最',
        'zun' => '尊', 'zuo' => '作'
    );

    public static function shouzhimu($chinese)
    {
        $result = '';
        $len = mb_strlen($chinese);
        for ($i = 0; $i < $len; $i++) {
            $char = mb_substr($chinese, $i, 1);
            foreach (self::$pinyinTable as $pinyin => $hanzi) {
                if (strpos($hanzi, $char)!== false) {
                    $result.= $pinyin[0];
                    break;
                }
            }
        }
        return $result;
    }

    public static function quanping($chinese)
    {
        $result = '';
        $len = mb_strlen($chinese);
        for ($i = 0; $i < $len; $i++) {
            $char = mb_substr($chinese, $i, 1);
            foreach (self::$pinyinTable as $pinyin => $hanzi) {
                if (strpos($hanzi, $char)!== false) {
                    $result.= $pinyin;
                    break;
                }
            }
        }
        return $result;
    }
}